<?php
class Selectorders extends Model
{
function Selectorders()
	{
		parent::Model();
		$this->_prefix = $this->config->item('FAL_table_prefix');
        $this->_table = $this->_prefix.'ordertable1';
        $this->_table_grocery = $this->_prefix.'grocery_order';
	}
	function getGrocery($id)
	{
		$this->db->where('userid',$id);
		$this->db->order_by('id','desc');
		return $this->db->get($this->_table_grocery);
	}
    function selectorderslist()
	{
		$userid = getUserId();
		//$this->db->where(array('date'=>$date));
		$this->db->where('userid', $userid); 
		$result = $this->db->get($this->_table);
		//print_r($result->result());
		return $result;
		
	}
	
	function searchbydate($date)
	{
		$userid = getUserId();
		$data = $this->selectorderslist();
		$datestring = "%m/%d/%Y";
		
	
		foreach ($data->result() as $res)
		{
			$time = $res->order_date;
			$formated_date = mdate($datestring, $time);
			 if(trim($formated_date) == trim($date))
			 {
			 	$search_results[] = $res;
			 }
		}
//		$grocery = $this->getGrocery($userid);
//		foreach($grocery->result() as $grocery_row)
//		{
//			$time = $grocery_row->ordered_date;
//			$formated_date = mdate($datestring, $time);
//			 if(trim($formated_date) == trim($date))
//			 {
//			 	$search_results_grocery[] = $grocery_row;
//			 }
//		}

		if(!isset($search_results))
		$search_results = array();
//		if(!isset($search_results_grocery))
//		$search_results_grocery = array();
//				print_r($search_results_grocery);
		return $search_results;
	}
}
?>

